package com.starbaba.core.service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.hibernate.type.Type;

import com.starbaba.core.hibernate.Page;
import com.starbaba.core.hibernate.QueryType;
import com.starbaba.core.hibernate.Strategy;
import com.starbaba.system.logaccess.model.LogAccessVO;
/**
 * 
 * <p>
 * Title: CommonService
 * </p>
 * 
 * </p>
 * 
 * @author liukangjin
 * @version 1.0
 * @since 2011-10-5
 *
 */
@SuppressWarnings("rawtypes")
public interface CommonService {
	
	/**
	 * 执行SQL 
	 * @param sql
	 * @param vo
	 * @return
	 *
	 * @Copyright: Copyright (c) 2006
	 * @Company: Revenco Tech Ltd.
	 * @anthor chenminhui<chenminhui@revenco.com>
	 * @since 2014-11-18 下午03:58:17
	 * @version V1.0
	 */
	public int executeSQLUpdate(String sql, Object... values);
	
	/**
	 * 执行HQL
	 * @param hql 
	 * @param values “?”参数数组
	 * @return 执行条数
	 *
	 * @Copyright: Copyright (c) 2006
	 * @Company: Revenco Tech Ltd.
	 * @anthor chenminhui<chenminhui@revenco.com>
	 * @since 2014-11-18 下午03:59:18
	 * @version V1.0
	 */
	public int executeHQLUpdate(String hql, Object... values);
	
	public int executeHQLUpdate(String hql, final Map<String, Object> params);
	
	public Object doCreate(Class<?> voClass, Object vo) throws Exception;

	public Object doUpdate(Class<?> voClass, Object vo) throws Exception;
	
	public void doRemoveByVO(Class<?> voClass, Object vo) throws Exception;

	public void doRemoveByPK(Class<?> voClass, Serializable pk) throws Exception;

	public Object doFindByPk(Class<?> voClass, Serializable pk) throws Exception;
	
	public List<?> doFindALL(Class<?> voClass) throws Exception;	

	public Page doQuery(Class<?> voClass, Object params) throws Exception;
	
	public Page doQuery(Class<?> voClass, Object params, QueryType queryType) throws Exception;
	
	public Page doQuery(Page page,String sql,Class<?> voClass, final Object... values) throws Exception;
	/**
	 * ======================================================================
	 * 以下方法为带日志记录日志方法
	 * ======================================================================
	 */
	public Object doCreate(Class<?> voClass, Object vo, Class<?> logClass, Object logVO) throws Exception;

	public void doRemoveByVO(Class<?> voClass, Object vo, Class<?> logClass, Object logVO) throws Exception;
	
	public void doRemoveByPK(Class<?> voClass, Serializable pk, Class<?> logClass, Object logVO) throws Exception;

	public Object doUpdate(Class<?> voClass, Object vo, Class<?> logClass, Object logVO) throws Exception;

	public Object doProcess(Strategy strategy) throws Exception;
	
	
	/**
	 * ======================================================================
	 * 特殊查询
	 * ======================================================================
	 */
	public List<?> doFindByExampleVO(Class<?> voClass, Object entity);
	
	public List<?> doFindByProperty(Class<?> voClass, String propertyName, Object propertyValue);
	
	public Object doFindMaxPropertyValle(Class<?> voClass, String propertyName);
	
	public List<?> doFindByHQL(final String hql, final Object... values);
	
	public List doFindBySQL(final String sql , final Map<String, Type> scalars , final Object... values);
	public List doFindByAliasSql(final String sql, Class<?> voClass, final Object... values) ;
	public Object findUniqueByHQL(final String hql, final Object... values);
	
	public List<?> findByHQL(final String hql, final Map<String, Object> params);
	
	public Object findUniqueByHQL(final String hql, final Map<String, Object> params);
	
	/**
	 * ======================================================================
	 * 创建操作日志
	 * ======================================================================
	/**
	 * 创建LogVO实体对象，子类可以重载该方法。
	 * @param userid 操作员工号
	 * @param accesstime 操作开始时间
	 * @param oprType 操作类型，默认是表对象名字
	 * @param action  操作类型，值可从类OperAction获得，如插入：OperAction.INSERT
	 * @param ip   操作IP
	 * @param oldVO 操作前对象值
	 * @param newVO 操作完毕后的对象值
	 * @param state 状态，值可从类OperState获得，如成功：OperState.SUCCESS
	 * @return
	 * @throws Exception
	 */
	public LogAccessVO createAccesslogVO(String userid, Date accesstime,String oprType,String action,String ip,Object oldVO,Object newVO,Long state) throws Exception;
}
